package com.example.scity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.scity.beens.MzyyBannerBeen;
import com.example.scity.beens.NewsInfoBeen;
import com.example.scity.beens.ShjfBannerBeen;
import com.example.scity.beens.WmdcBannerBeen;
import com.google.gson.Gson;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class MzyyActivity extends AppCompatActivity {
    Banner mzyybanner;
    List<String> imglist=new ArrayList<>();
    Handler handler=new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            handlerbanner();
        }
    };

    LinearLayout linearLayoutksfk;
    private void handlerbanner() {
        mzyybanner.setImages(imglist);
        mzyybanner.setImageLoader(new ImageLoader() {
            @Override
            public void displayImage(Context context, Object o, ImageView imageView) {
                Glide.with(context).load(o).into(imageView);
            }
        });
        mzyybanner.setDelayTime(2000);
        mzyybanner.start();
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mzyy);
        mzyybanner=findViewById(R.id.mzyy_banner);
        loadmzyybanner();
        linearLayoutksfk();
        linearlayout_yy();
        linearlayout_jzk();
    }

    private void linearLayoutksfk() {
        linearLayoutksfk=findViewById(R.id.linearlayout_ksgl);
        linearLayoutksfk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MzyyActivity.this,MzyyKsflActivity.class));
            }
        });
    }
    private void linearlayout_yy() {
        linearLayoutksfk=findViewById(R.id.linearlayout_yy);
        linearLayoutksfk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MzyyActivity.this,MzyyYuYueActivity.class));
            }
        });
    }
    private void linearlayout_jzk() {
        linearLayoutksfk=findViewById(R.id.linearlayout_jzk);
        linearLayoutksfk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MzyyActivity.this,MzyyJzkActivity.class));
            }
        });
    }
    private void loadmzyybanner() {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder().url(Configs.Host+ APIInterface.MzyyBannerList).build();
        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {

            }

            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
                MzyyBannerBeen json = new Gson().fromJson(response.body().string(), MzyyBannerBeen.class);
                for (int i = 0;i<json.data.size();i++){
                    imglist.add(Configs.Host+json.data.get(i).imgUrl);
                }
                handler.sendEmptyMessage(1);
            }
        });
    }
}